﻿using System.Collections.Generic;
using System.Linq;
using ATTools.Models;
using ATTools.Services;
using ATTools.ViewModels;
using Orchard;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Environment.Extensions;
using Orchard.Localization;
using Orchard.Settings;


namespace ATTools.Drivers
{
    [OrchardFeature("ATTools")]
    public class ATToolsSettingsDriver : ContentPartDriver<ATToolsSettingsPart>
    {

        protected override string Prefix { get { return "ATToolsSettings"; } }

        protected override DriverResult Editor(ATToolsSettingsPart part, dynamic shapeHelper)
        {

            var model = new ATToolsSiteSettingsPartViewModel
            {
                Part = part,
            };

            return ContentShape("Parts_ATTools_SiteSettings",
                               () => shapeHelper.EditorTemplate(TemplateName: "Parts/SiteSettings", Model: model, Prefix: Prefix));
        }


        protected override DriverResult Editor(ATToolsSettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part.Record, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}